package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.iotDevice.IotDeviceGetModel;
import com.hzhr.iot.device.model.iotDevice.IotDevicePutModel;
import com.hzhr.iot.device.service.IotDeviceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "IotDevice", description = "物联网设备")
@RestController
@RequestMapping(value = "")
public class IotDeviceController extends BaseController {
    @Autowired
    IotDeviceService iotDeviceService;

    //region /iot-devices GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="查询用户管辖范围下的物联网设备", notes="查询用户管辖范围下的物联网设备  \n步骤 :  \n1. 查询物联网设备：  \n 如果登录用户是燃气公司用户，可查询用户管辖范围下的物联网设备；  \n 如果登录用户是物联网公司用户，可查询用户所在公司下的物联网设备；  \n 如果是全局用户(用户编号为0)，可查询所有物联网设备；  \n2. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_company", value = "是否展示所属公司信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_gasCompany", value = "是否展示所属燃气公司信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_outId", value = "是否展示外部系统唯一键", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where iotDevice.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where iotDevice.code = #{equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_categoryCode", value = "筛选条件 : where iotDevice.categoryCode = #{equal_categoryCode}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_iotPlatformImei", value = "筛选条件 : where iotDevice.iotPlatformImei = #{equal_iotPlatformImei}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_iotPlatformDeviceId", value = "筛选条件 : where iotDevice.iotPlatformDeviceId = #{equal_iotPlatformDeviceId}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_code", value = "筛选条件 : where iotDevice.code like #{like_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isnull_gasCompanyId", value = "筛选条件 : where iotDevice.gasCompanyId is (not) null",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_createTime", value = "筛选条件 : where iotDevice.createTime >= #{greaterthanorequal_createTime}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "lessthan_createTime", value = "筛选条件 : where iotDevice.createTime < #{lessthan_createTime}",required = false, dataType = "long", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_company", value = "是否展示所属公司信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_gasCompany", value = "是否展示所属燃气公司信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_outId", value = "是否展示外部系统唯一键", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where iotDevice.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where iotDevice.code = #{_equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_categoryCode", value = "筛选条件 : where iotDevice.categoryCode = #{_equal_categoryCode}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_iotPlatformImei", value = "筛选条件 : where iotDevice.iotPlatformImei = #{_equal_iotPlatformImei}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_iotPlatformDeviceId", value = "筛选条件 : where iotDevice.iotPlatformDeviceId = #{_equal_iotPlatformDeviceId}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_resourceCode", value = "筛选条件 : where iotDevice.resourceCode like #{_like_resourceCode}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_code", value = "筛选条件 : where iotDevice.code like #{_like_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_isnull_gasCompanyId", value = "筛选条件 : where iotDevice.gasCompanyId is (not) null",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_createTime", value = "筛选条件 : where iotDevice.createTime >= #{_greaterthanorequal_createTime}",required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "_lessthan_createTime", value = "筛选条件 : where iotDevice.createTime < #{_lessthan_createTime}",required = false, dataType = "long", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/iot-devices", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<IotDeviceGetModel> get(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        IotDeviceGetModel responseBody = iotDeviceService.get(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /iot-devices/{id} PUT
    //region swagger响应码 : putById
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询物联网设备  \n----异常说明 : 物联网设备不存在  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证新的物联网设备代码  \n----异常说明 : 物联网设备代码已存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : putById
    @ApiOperation(value="更新物联网设备", notes="更新物联网设备  \n简介 : 更新物联网设备  \n步骤 :  \n1. 查询物联网设备 ; (√)  \n 根据路径参数id查询物联网设备(IOT_DEVICE)iotDevice_1,  \n 路径参数查询筛选规则：  \n          (1) iotDevice_1.id = id；  \n 如果iotDevice_1不存在，抛出异常201；  \n2. 验证新的物联网设备代码 : (√)  \n如果body.code != iotDevice_1.code，且存在某个物联网设备(IOT_DEVICE)对象iotDevice满足iotDevice.code = body.code，则抛出异常202；  \n3. 更新物联网设备的注册信息 : (√)  \n根据body更新iotDevice_1的相关信息；  \n4. 返回信息 : (√)  \n根据条件参数查询iotDevice_1更新后的信息，然后生成结果对象并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : putById
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "id", value = "物联网设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),

    })
    //endregion
    //region 请求 : putById
    @RequestMapping(value = "/iot-devices/{id}", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<IotDeviceGetModel> putById(@PathVariable("id") Integer id,
                                                     @RequestParam @ApiIgnore Map<String, Object> query,
                                                     @RequestBody IotDevicePutModel body) throws ServiceException {
        IotDeviceGetModel responseBody = iotDeviceService.putById(initHeader(), id, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}
















































































































































































































































































































































































































































































































































































































































































